<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="../common/head.jsp"%>
<%@taglib prefix="from" uri="http://www.springframework.org/tags/form" %>
<script src="/js/jquery-1.8.3.min.js"></script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面 >> 用户添加页面</span>
    </div>
    <script>
        function baoCun(){
            var flag = false;
            var userCode = $("#userCode").val();
            var userName = $("#userName").val();
            var userPassword = $("#userPassword").val();
            var ruserPassword = $("#ruserPassword").val();
            var birthday = $("#birthday").val();
            var phone = $("#phone").val();
            var address = $("#address").val();
            if (userCode == "" || userName == "" || userPassword == "" || ruserPassword == "" || birthday == "" || phone == "" || address == ""){
                $("#tiShi").text("请完善信息再进行添加!")
                return flag;
            }
            $.ajax({
                type:"post",//请求类型
                url:"doUserCode",//请求的url
                data:{
                    userCode:$("#userCode").val()
                }, dataType:"json",//ajax接口（请求url）返回的数据类型
                async:false,//是否位同步,true(默认值):异步false:同步
                success:function(data){//data：返回数据（json对象）
                    if (data == "1") {
                        $("#userCodeTiShi").text("此编码已存在!")
                        flag = false;
                    }else {
                        $("#userCodeTiShi").text("")
                        flag = true;
                    }
                },
            });
            return flag
        }
    </script>
    <div class="providerAdd">
        <from:form modelAttribute="user" enctype="multipart/form-data" id="userForm" name="userForm" method="post" action="doAdd" onsubmit="return baoCun()">
            <input type="hidden" name="method" value="add">
            <!--div的class 为error是验证错误，ok是验证成功-->
           <div>
                <label for="userCode">用户编码：</label>
                <input type="text" name="userCode" id="userCode" value="">
                <!-- 放置提示信息 -->
                <font color="red" id="userCodeTiShi"></font>
            </div>
            <div>
                <label for="userName">用户名称：</label>
                <input type="text" name="userName" id="userName" value="">
                <font color="red"><from:errors path="userName"/></font>
            </div>
            <div>
                <label for="userPassword">用户密码：</label>
                <input type="password" name="userPassword" id="userPassword" value="">
                <font color="red"><from:errors path="userPassword"/></font>
            </div>
            <div>
                <label for="ruserPassword">确认密码：</label>
                <input type="password" name="ruserPassword" id="ruserPassword" value="">
                <font color="red"></font>
            </div>
            <div>
                <label >用户性别：</label>
                <select name="gender" id="gender">
                    <option value="1" selected="selected">男</option>
                    <option value="2">女</option>
                </select>
            </div>
            <div>
                <label for="birthday">出生日期：</label>
                <input type="text" Class="Wdate" id="birthday" name="birthday"
<%--                       readonly="readonly" onclick="WdatePicker();">--%>
                <font color="red"><from:errors path="birthday"/></font>
            </div>
            <div>
                <label for="phone">用户电话：</label>
                <input type="text" name="phone" id="phone" value="">
<%--                <font color="red"><from:errors path="phone"/></font>--%>
            </div>
            <div>
                <label for="address">用户地址：</label>
                <input name="address" id="address"  value="">
            </div>
            <div>
                <label >用户角色：</label>
                <!-- 列出所有的角色分类 -->
                <select name="userRole" id="userRole">
                    <c:if test="${requestScope.roleList != null}">
                        <c:forEach items="${requestScope.roleList}" var="role">
                            <option value="${role.roleId}">${role.roleName}</option>
                        </c:forEach>
                    </c:if>
                </select>
                <font color="red" id="tiShi"></font>
            </div>
            <div>
                <label for="pic">头像：</label>
                <input name="pic" id="pic" type="file">
                <input name="pic" type="file">
            </div>
            <div class="providerAddBtn">
                <input type="submit" name="add" id="add" value="保存" >
                <input type="button" id="back" name="back" onclick="history.go(-1)" value="返回" >
            </div>
        </from:form>
    </div>
</div>
</section>
<%@include file="../common/foot.jsp" %>
<%--<script type="text/javascript" src="${pageContext.request.contextPath }/js/useradd.js"></script>--%>

